package com.example.adms.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.adms.system.entity.System;
import com.example.adms.system.mapper.SystemMapper;
import com.example.adms.system.service.SystemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyt
 * @since 2023-04-25
 */
@Service
public class SystemServiceImpl extends ServiceImpl<SystemMapper, System> implements SystemService {
    @Autowired
    SystemMapper systemMapper;

    @Override
    public boolean alterSystemTime(int leTime, int leaveTime) {
        List<System> systems = systemMapper.selectList(null);
        this.remove(new QueryWrapper<>());
        systems.set(0,new System(leTime,leaveTime));
        System system = systems.get(0);
        int result = systemMapper.insert(system);
        if (result == 1){
            return true;
        }
        else{
            return false;
        }
    }

    @Override
    public Map<String, Integer> getSystemTime() {
        System system = systemMapper.selectOne(null);
        Map<String, Integer> map = new HashMap<>();
        map.put("leTime",system.getLeTime());
        map.put("leaveTime",system.getLeaveTime());
        return map;
    }

}
